package com.fortune.rainshineservice.controller;

import com.fortune.rainshinecommon.base.MsgModel;
import com.fortune.rainshinecommon.base.ParmsModel;
import com.fortune.rainshinecommon.model.ShopModel;
import com.fortune.rainshinecommon.model.system.User;
import com.fortune.rainshinecommon.query.ShopQuery;
import com.fortune.rainshineservice.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: rainShine
 * @description: 加盟店控制器
 * @author: tangyn
 * @create: 2019-03-06
 **/
@RestController
@RequestMapping("/shop")
public class ShopController {
    @Autowired
    private IShopService iShopService;

    @PostMapping("/createShop")
    public MsgModel createShop(@RequestBody ShopModel shopModel){
        return iShopService.createShop(shopModel);
    }

    @PostMapping("/updateShop")
    public MsgModel updateShop(@RequestBody ShopModel shopModel){
        return iShopService.updateShop(shopModel);
    }

    @PostMapping("/shopList")
    public MsgModel shopList(@RequestBody ParmsModel parms){
        return iShopService.shopList(parms);
    }

    @PostMapping("/delShop")
    public MsgModel delShop(@RequestBody ShopModel shopModel){
        return iShopService.delShop(shopModel);
    }

    @PostMapping("/stopShop")
    public MsgModel stopShop(@RequestBody ShopModel shopModel){
        return iShopService.stopShop(shopModel, "test");
    }

    @PostMapping("/shopsByUserId")
    public List<ShopModel> getShopsByUserId(@RequestBody Integer userId){
        return iShopService.getShopsByUserId(userId);
    }
    
    @PostMapping("/shopsByUserId2")
    public List<ShopModel> getShopsByUserId2(@RequestBody Integer userId){
        return iShopService.getShopsByUserId2(userId);
    }

    @PostMapping("/getShopInfoById")
    public MsgModel getShopInfoById(@RequestBody ShopQuery query){
        return iShopService.getShopInfoById(query.getShopId());
    }

    @PostMapping("/appGetUserShopList")
    public MsgModel appGetUserShopList(@RequestBody ShopQuery query){
        return iShopService.appGetUserShopList(query);
    }

    @PostMapping("/getMapShops")
    public List<ShopModel> getMapShops(@RequestBody ShopQuery query){
        return iShopService.getMapShops(query.getCityCode());
    }
    
    @PostMapping("/getShopByShopId")
    public ShopModel getShopByShopId(@RequestBody Integer shopId){
        return iShopService.getShopByShopId(shopId);
    }

    /**
     * 通过id获取正常营业的商铺
     * @param shopId
     * @return
     */
    @PostMapping("/getShopByShopId2")
    public ShopModel getShopByShopId2(@RequestBody Integer shopId){
    	ShopModel shop = iShopService.getShopByShopId(shopId);
    	if(shop.getShopStatus() == 0) {
    		return new ShopModel();
    	}
        return shop;
    }
    
    @PostMapping("/getByShopName")
    public ShopModel getByShopName(@RequestBody String name){
        return iShopService.getByShopName(name);
    }

    @PostMapping("/getShopByShopLevel")
    public List<ShopModel> getShopByShopLevel(@RequestBody Integer shopLevel){
        return iShopService.getShopByShopLevel(shopLevel);
    }
    
    @PostMapping("/getShopByMerchantsId")
    public List<ShopModel> getShopByMerchantsId(@RequestBody Integer merchantsId){
        return iShopService.getShopByMerchantsId(merchantsId);
    }

    @PostMapping("/getServiceRecordShops")
    public MsgModel getServiceRecordShops(@RequestBody ParmsModel parm){
        return iShopService.getServiceRecordShops(parm);
    }

    @PostMapping("/getShopsByMerchants")
    public MsgModel getShopsByMerchants(@RequestBody ParmsModel parm){
        return iShopService.getShopsByMerchants(parm);
    }

    /**
     * 获取所有加盟店列表
     * @param parm
     * @return
     */
    @PostMapping("/getAllLevel3Shops")
    public MsgModel getAllLevel3Shops(@RequestBody ParmsModel parm){
        return iShopService.getAllLevel3Shops(parm);
    }


    /**
     * 获取门店的所有在职人员（包括店长）
     * @param shopId
     * @return
     */
    @PostMapping("/getAllUsersByShopId")
    public List<User> getAllUsersByShopId(@RequestBody Integer shopId){
        return iShopService.getAllUsersByShopId(shopId);
    }
}
